﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Security;
using System.IO;
using System.Web;
using System.Xml;
using System.Reflection;
using System.Linq;

namespace YTBZ.PUB.Common
{
    public class StringHelper
    {
        // Methods
        /// <summary>
        /// 去了文本里的html代码
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        public static string clearHtml(string html)
        {
            if (html != null)
            {
                return Regex.Replace(Regex.Replace(html, "<[^>]*>", ""), @"\s+", " ").Replace("&nbsp;", " ");
            }
            return "";
        }

        /// <summary>
        /// 点击提交按钮后执行,如可以显示动画效果提示后台处理进度
        /// </summary>
        /// <param name="page">page</param>
        /// <param name="Button1">按钮</param>
        public static void SetUIStyle(System.Web.UI.Page page, System.Web.UI.WebControls.Button Button1)
        {
            //sb保存的是JavaScript脚本代码,点击提交按钮时执行该脚本
            StringBuilder sb = new StringBuilder();
            if (Button1.PostBackUrl != "")
            {
            }
            else
            {
                sb.Append(" if (TimeControl()==false) { return false ;}; ");
                if (string.IsNullOrEmpty(Button1.ValidationGroup))
                {
                    if (!string.IsNullOrEmpty(Button1.Attributes["SPYJ"]))
                    {
                        sb.Append("if (allLength()==false) { return false; } else if(" + Button1.Attributes["SPYJ"] + "==false) { return false;};");
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(Button1.Attributes["identifier"]))
                        {
                            sb.Append("if (typeof(Page_ClientValidate) == 'function') { if (Page_ClientValidate() == false||allLength()==false) { return false; } else GetEventSave();};");
                        }
                        else
                        {
                            //保证验证函数的执行 
                            sb.Append("if (typeof(Page_ClientValidate) == 'function') { if (Page_ClientValidate() == false|| allLength()==false) { return false; }};");
                        }
                    }
                }
                else
                {

                    if (!string.IsNullOrEmpty(Button1.Attributes["identifier"]))
                    {
                        sb.Append("if (typeof(Page_ClientValidate) == 'function') { if (Page_ClientValidate('" + Button1.ValidationGroup.ToString() + "') == false||allLength()==false) { return false; } else if(GetEventSave()==false) { return false;}};");
                    }

                    else
                    {

                        sb.Append("if (typeof(Page_ClientValidate) == 'function') { if (Page_ClientValidate('" + Button1.ValidationGroup.ToString() + "') == false||allLength()==false) { return false; }};");
                    }
                }
                //点击提交按钮后设置Button的disable属性防止用户再次点击,注意这里的this是JavaScript代码
                sb.Append("this.disabled  = true;");
                //用__doPostBack来提交，保证按钮的服务器端click事件执行 
                sb.Append(page.ClientScript.GetPostBackEventReference(Button1, ""));
                sb.Append(";");
                //SetUIStyle()是JavaScript函数,点击提交按钮后执行,如可以显示动画效果提示后台处理进度

                //注意SetUIStyle()定义在aspx页面中
                //sb.Append("SetUIStyle();");
                //给提交按钮增加OnClick属性
                Button1.Attributes.Add("OnClick", sb.ToString());
            }
        }

        /// <summary>
        /// 字符串加密
        /// </summary>
        /// <param name="passwordString"></param>
        /// <param name="encryptMode"></param>
        /// <returns></returns>
        public static string EncryptPassword(string passwordString, EncryptMode encryptMode)
        {
            switch (encryptMode)
            {
                case EncryptMode.SHA1:
                    return FormsAuthentication.HashPasswordForStoringInConfigFile(passwordString, EncryptMode.SHA1.ToString());

                case EncryptMode.MD5:
                    return FormsAuthentication.HashPasswordForStoringInConfigFile(passwordString, EncryptMode.MD5.ToString());
            }
            return "";
        }

        /// <summary>
        /// MD5加密码
        /// </summary>
        /// <param name="passwordString"></param>
        /// <returns></returns>
        public static string EncryptPasswordWithMD5(string passwordString)
        {
            return EncryptPassword(passwordString, EncryptMode.MD5);
        }

        /// <summary>
        /// 格式化xml
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string FormatForXml(object input)
        {
            if (input == null)
            {
                return "";
            }
            return input.ToString().Replace("&", "&amp;").Replace("/", "&quot;").Replace("'", "&qapos;").Replace("<", "&lt;").Replace(">", "&gt");
        }

        /// <summary>
        /// 格式化手机如:15058190285格式化后是150****0285
        /// </summary>
        /// <param name="mobile">手机号</param>
        /// <returns></returns>
        public static string FormatShowMobile(string mobile)
        {
            mobile = mobile.Trim();
            string pattern = @"(86)?\d{11}";
            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
            if (regex.IsMatch(mobile))
            {
                string str2 = @"(86)?(\d{3})(\d{4})(\d+)";
                return Regex.Replace(mobile, str2, "${1}${2}****${4}");
            }
            return mobile;
        }

        /// <summary>
        /// 格式化人的名字如:胡波 格式化后是 胡*
        /// </summary>
        /// <param name="name">人的名字</param>
        /// <returns></returns>
        public static string FormatShowName(string name)
        {
            if (!string.IsNullOrEmpty(name))
            {
                return name.Substring(0, 1).PadRight(name.Length, '*');
            }
            return "";
        }


        /// <summary>
        /// 格式化人的名字如:胡波 格式化后是 胡 波 
        /// </summary>
        /// <param name="name">人的名字</param>
        /// <returns></returns>
        public static string FormatShowName(string name ,string sep)
        {
            string res = string.Empty;
            if (!string.IsNullOrEmpty(name))
            {
                if (IsCN(name))
                {
                    switch (name.Length)
                    {
                        case 1://名字长度是１的

                            res = sep + name[0] + sep;
                            break;
                        case 2://名字长度是２
                            res = name[0] + sep + name[1];
                            break;
                        default:
                            res = name;
                            break;
                    }
                }
                else
                {
                    res = name;
                }
            }
            return res;
        }

        /// <summary>
        /// 格式化人的名字如:胡波 格式化后是 胡 波 
        /// </summary>
        /// <param name="name">人的名字</param>
        /// <returns></returns>
        public static string FormatName(string name)
        {
            return FormatShowName(name, "&nbsp;&nbsp;");
        }

        /// <summary>
        /// 把字符串转化成bool型:如"1"和"true"就返回真
        /// </summary>
        /// <param name="str">要转化字符串</param>
        /// <returns></returns>
        public static bool GetBool(string str)
        {
            return GetBool(str, false);
        }

        public static bool GetBool(string str, bool var)
        {
            if (!string.IsNullOrEmpty(str))
            {
                return ((str == "1") || (str.ToLower() == "true"));
            }
            return var;
        }
        /// <summary>
        /// 转化成双精度
        /// </summary>
        /// <param name="str">转化的对象</param>
        /// <returns></returns>
        public static double GetDouble(object str)
        {
            string str2;
            double var = 0.0;
            if (str != null)
            {
                str2 = str.ToString();
            }
            else
            {
                str2 = "";
            }
            return GetDouble(str2, var);
        }
        /// <summary>
        /// 转化成双精度
        /// </summary>
        /// <param name="str">要转化的字符串</param>
        /// <returns></returns>
        public static double GetDouble(string str)
        {
            double var = 0.0;
            return GetDouble(str, var);
        }
        /// <summary>
        /// 转化成双精度 如果不能转换就用后面那个默认值var
        /// </summary>
        /// <param name="str">要转化的字符串</param>
        /// <param name="var">转化不成功时的默认值</param>
        /// <returns></returns>
        public static double GetDouble(string str, double var)
        {
            if ((str != null) && (str != ""))
            {
                return (IsDouble(str) ? double.Parse(str) : var);
            }
            return var;
        }
        /// <summary>
        /// 文本转成html的格式
        /// </summary>
        /// <param name="strContent">要转的文本</param>
        /// <returns></returns>
        public static string GetHtmlFormat(string strContent)
        {
            if (strContent == null)
            {
                return "";
            }
            strContent = strContent.Replace("\r\n", "<br>"); 
            strContent = strContent.Replace("\n", "<br>"); 
            strContent = strContent.Replace(" ", "&nbsp;");
            return strContent;
        }

       
        /// <summary>
        /// 得到整型
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        public static int GetInt(double d)
        {
            return Convert.ToInt32(Math.Ceiling(d));
        }
        /// <summary>
        /// 得到整型
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static int GetInt(object str)
        {
            string str2;
            int var = 0;
            if (str != null)
            {
                str2 = str.ToString();
            }
            else
            {
                str2 = "";
            }
            return GetInt(str2, var);
        }
        /// <summary>
        /// 得到整型
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static int GetInt(string str)
        {
            int var = 0;
            return GetInt(str, var);
        }
        /// <summary>
        /// 得到整型
        /// </summary>
        /// <param name="str"></param>
        /// <param name="var">如果没转成功时给定的默认值</param>
        /// <returns></returns>
        public static int GetInt(string str, int var)
        {
            if ((str != null) && (str != ""))
            {
                return (IsNum(str) ? int.Parse(str) : var);
            }
            return var;
        }

        private string GetRegContent(string sContent, string sRegex, string sGroup)
        {
            string str = "";
            if (sContent == string.Empty)
            {
                return "";
            }
            Match match = new Regex(sRegex, RegexOptions.Compiled | RegexOptions.IgnoreCase).Match(sContent);
            if (match.Success)
            {
                try
                {
                    str = match.Groups[sGroup].Value.Trim();
                }
                catch
                {
                    str = "";
                }
            }
            return str;
        }

        /// <summary>
        /// 把字符串里的英文下的'换成＇;换成；
        /// </summary>
        /// <param name="intStr"></param>
        /// <returns></returns>
        public static string GetSafeString(int intStr)
        {
            return GetSafeString(intStr.ToString());
        }
        /// <summary>
        /// 把字符串里的英文下的'换成＇;换成；
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string GetSafeString(string str)
        {
            if ((str != "") || (str != null))
            {
                return str;//.Replace("'", "＇").Replace(";", "；");
            }
            return "";
        }
        /// <summary>
        /// 截取字符串的前len位并在后面加上"..."
        /// </summary>
        /// <param name="str">要截取的字符串</param>
        /// <param name="len">长度</param>
        /// <returns></returns>
        public static string GetSubStr(string str, int len)
        {
            return GetSubStr(str, len, "...");
        }



        /// <summary>
        /// 截取字符串的前len位并在后面加上"..."
        /// </summary>
        /// <param name="str">要截取的字符串</param>
        /// <param name="len">长度</param>
        /// <param name="sep">后面要代替的字符串如...</param>
        /// <returns></returns>
        public static string GetSubStr(string srcStr, int limitedNum, string sep)
        {
            if (limitedNum <= 0)
            {
                return srcStr;
            }
            byte[] bytes = Encoding.GetEncoding("GB2312").GetBytes(srcStr);
            if (bytes.Length <= limitedNum)
            {
                return srcStr;
            }
            byte[] destinationArray = null;
            int length = (bytes[limitedNum] > 0x7f) ? (limitedNum + 1) : limitedNum;
            destinationArray = new byte[length];
            Array.Copy(bytes, destinationArray, length);
            return (Encoding.GetEncoding("GB2312").GetString(destinationArray) + sep);
        }
        /// <summary>
        /// 截取字符串的前len位并在后面加上"..."
        /// </summary>
        /// <param name="str">要截取的字符串</param>
        /// <param name="length">长度</param>
        /// <returns></returns>
        public static string GetSubString(string str, int length)
        {
            if ((str != null) && (str != ""))
            {
                if (length <= 0)
                {
                    return "";
                }
                int num = 0;
                int num2 = 0;
                foreach (char ch in str)
                {
                    if (ch > '\x007f')
                    {
                        num += 2;
                    }
                    else
                    {
                        num++;
                    }
                    if (num > length)
                    {
                        str = str.Substring(0, num2) + "...";
                        return str;
                    }
                    num2++;
                }
            }
            return str;
        }

        /// <summary>
        /// 给字符串加上指定长度的字符，如将1加为0001
        /// </summary>
        /// <param name="str">需要加的原字符串</param>
        /// <param name="length">定长的长度</param>
        /// <param name="sep">需加的字符</param>
        /// <param name="align">加前left,加后right</param>
        /// <returns></returns>
        public static string GetAddLenString(string str, int length, string sep, string align)
        {
            string strtemp = str;
            if (str.Length < length)
            {
                for(int i=str.Length ;i<length;i++ )
                {
                    if (align == "right")
                    {
                        strtemp += sep;
                    }
                    else
                    {
                        strtemp = sep + strtemp;
                    }
                }
            }
            return strtemp;
        }


        /// <summary>
        /// 得到html里的title标题
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        public static string GetTitle(string html)
        {
            Match match = Regex.Match(html, "<title>(.*)</title>");
            if (match.Groups.Count == 2)
            {
                return match.Groups[1].Value;
            }
            return "(unknown)";
        }
        /// <summary>
        /// 得到站点的虚拟路径
        /// </summary>
        /// <returns></returns>
        public static string GetWebPath()
        {
            string applicationPath = HttpContext.Current.Request.ApplicationPath;
            if (applicationPath != "/")
            {
                applicationPath = applicationPath + "/";
            }
            return applicationPath;
        }

        public static string GetWebPath(string localPath)
        {
            string applicationPath = HttpContext.Current.Request.ApplicationPath;
            if (applicationPath != "/")
            {
                applicationPath = applicationPath + "/";
            }
            if (localPath.StartsWith("~/"))
            {
                localPath = localPath.Substring(2);
            }
            return (applicationPath + localPath);
        }

       

        /// <summary>
        /// 字符串里是否有中文
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsCHZN(string str)
        {
            string pattern = @"[\u4e00-\u9fa5]";
            return Regex.IsMatch(str, pattern);
        }


        /// <summary>
        /// 需要引入 System.Text.RegularExpressions 命名空间
        /// </summary>
        /// <param name="strInput">待验证的字符串</param>
        /// <returns>是中文返回true,否则false</returns>
        public static bool IsCN(string strInput)
        {
            Regex reg = new Regex("^[\u4e00-\u9fa5]+$");

            return reg.IsMatch(strInput);
        }

        /// <summary>
        /// 是否是双精度
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsDouble(string str)
        {
            string pattern = @"^\d+(\.\d+)?$";
            return Regex.IsMatch(str, pattern);
        }
        /// <summary>
        /// 是否是Email
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsEmail(string str)
        {
            string pattern = @"^[\\w-]+@[\\w-]+\\.(com|net|org|edu|mil|tv|biz|info)$";
            return Regex.IsMatch(str, pattern);
        }
        /// <summary>
        /// 是否是钱的格式0.00
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsMoney(string str)
        {
            string pattern = @"^\d+(\.\d{2})?$";
            return Regex.IsMatch(str, pattern);
        }
        /// <summary>
        /// 是否是数字
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsNum(string str)
        {
            string pattern = @"^-?\d+$";
            return Regex.IsMatch(str, pattern);
        }



        /// <summary>
        /// 是否是数字
        /// </summary>
        /// <param name="strNumber"></param>
        /// <returns></returns>
        public static bool IsNumber(string strNumber)
        {
            return new Regex(@"^([0-9])[0-9]*(\.\w*)?$").IsMatch(strNumber);
        }



        /// <summary>
        /// 首字母小字
        /// </summary>
        /// <param name="letter"></param>
        /// <returns></returns>
        public static string LowerFirstLetter(string letter)
        {
            return (letter.Substring(0, 1).ToLower() + letter.Substring(1, letter.Length - 1));
        }

        public string ReplaceKeyWords(Match m)
        {
            return ("<span class=highlight>" + m.Value + "</span>");
        }

        public static string ReplaceQuerySpace(string str)
        {
            string newValue = " ";
            str = str.Replace(",", newValue);
            str = str.Replace(";", newValue);
            str = str.Replace("　", newValue);
            str = str.Replace("，", newValue);
            str = str.Replace("；", newValue);
            str = str.Replace("、", newValue);
            return str;
        }

        
        public static string[] SplitString(string strContent, string strSplit)
        {
            int index = strContent.IndexOf(strSplit);
            if (strContent.IndexOf(strSplit) < 0)
            {
                return new string[] { strContent };
            }
            return Regex.Split(strContent, strSplit.Replace(".", @"\."));
        }
        /// <summary>
        /// 把字符串转成float的
        /// </summary>
        /// <param name="strValue">要转化的值</param>
        /// <param name="defValue">转化不成功返回的默认值</param>
        /// <returns></returns>
        public static float StrToFloat(object strValue, float defValue)
        {
            if ((strValue == null) || (strValue.ToString().Length > 10))
            {
                return defValue;
            }
            float num = defValue;
            if ((strValue != null) && new Regex(@"^([-]|[0-9])[0-9]*(\.\w*)?$").IsMatch(strValue.ToString()))
            {
                num = Convert.ToSingle(strValue);
            }
            return num;
        }
        /// <summary>
        /// 转化成时间
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        /// <summary>
        /// 把object转成int
        /// </summary>
        /// <param name="strValue">object</param>
        /// <returns></returns>
        public static int StrToInt(object strValue)
        {
            int defValue = -1;
            return StrToInt(strValue, defValue);
        }
        /// <summary>
        /// 把字符串转成int的
        /// </summary>
        /// <param name="strValue">源字符串</param>
        /// <param name="defValue">转化不成功返回的默认值</param>
        /// <returns></returns>
        public static int StrToInt(object strValue, int defValue)
        {
            if (((strValue == null) || (strValue.ToString() == string.Empty)) || (strValue.ToString().Length > 10))
            {
                return defValue;
            }
            string str = strValue.ToString();
            string strNumber = str[0].ToString();
            if (((str.Length == 10) && IsNumber(strNumber)) && (int.Parse(strNumber) > 1))
            {
                return defValue;
            }
            if (!((str.Length != 10) || IsNumber(strNumber)))
            {
                return defValue;
            }
            int num = defValue;
            if ((strValue != null) && new Regex("^([-]|[0-9])[0-9]*$").IsMatch(strValue.ToString()))
            {
                num = Convert.ToInt32(strValue);
            }
            return num;
        }

        #region 移除不安全SQL代码 刘金林 添加
        /// <summary>
        /// 移除不安全代码
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public static string RemoveUnsafeSQL(string strInput)
        {
            if (strInput == "")
                return strInput;
            //string strKeyWord = @"select|insert|delete|from|count(|drop table|update|truncate|asc(|mid(|char(|xp_cmdshell|exec master|netlocalgroup administrators|net user|or|and";
            string strKeyWord = @"--|select|insert|delete|from|count|drop table|update|truncate|asc|mid|char|xp_cmdshell|exec master|netlocalgroup administrators|net user|or|and";
            //string strRegex = @"[;|/|(|)|}|{|%|@|!|']";
            string strRegex = @"[%|@|']";
            strInput = System.Text.RegularExpressions.Regex.Replace(strInput, strKeyWord, "",RegexOptions.IgnoreCase);
            strInput = System.Text.RegularExpressions.Regex.Replace(strInput, strRegex, "", RegexOptions.IgnoreCase);
            return strInput;
            //string[] strArrayKeyWord = strKeyWord.Split(new char[]{'|'}, System.StringSplitOptions.RemoveEmptyEntries);
            //string[] strArrayRegex = strRegex.Split(new char[] { '|' }, System.StringSplitOptions.RemoveEmptyEntries);
            //strInput = strInput.ToLower();
            //foreach (string str in strArrayKeyWord)
            //{
            //    strInput = strInput.Replace(str, "");
            //}
            //foreach (string str in strArrayRegex)
            //{
            //    strInput = strInput.Replace(str, "");
            //}
            //strInput = strInput.Replace("--", " ").Replace("'", "&qapos;");
        }
        #endregion

        // 加密的方式

        public enum EncryptMode
        {
            SHA1,
            MD5
        }

        #region 密码加密
        /// <summary>
        /// 密码加密
        /// </summary>
        /// <param name="M_Info"></param>
        /// <returns></returns>
        public static string AddSec(string M_Info)
        {
            int Num = M_Info.Length;
            int Allnum = 0;
            int Chg;
            int Other;
            string Pass = "";
            string OtherPass = "";
            if (Num != 0)
            {
                for (int i = 0; i < Num; i++)
                {
                    Allnum += (int)Convert.ToChar(M_Info.Substring(Num - i - 1, 1).ToString());
                }
                Allnum = Allnum * 2;
                for (int i = 0; i < Num; i++)
                {
                    Chg = Allnum % 26;
                    Allnum = Allnum - (int)Convert.ToChar(M_Info.Substring(Num - i - 1, 1).ToString());
                    Pass += Convert.ToChar((int)'A' + Chg);
                }
                Other = 12 - Num;
                Allnum = Allnum * 3;
                for (int i = 0; i < Other; i++)
                {
                    Chg = Allnum % 26;
                    Allnum -= Chg * 3;
                    OtherPass += Convert.ToChar((int)'A' + Chg);
                }
                return OtherPass + Pass;

            }
            else
            {
                return "";
            }

        }
        #endregion

        public static string strWebServer()
        {
            string webpath = "http://" + System.Web.HttpContext.Current.Request.Url.Authority + System.Web.HttpContext.Current.Request.ApplicationPath;
            if (webpath[webpath.Length - 1] != '/')
            {
                webpath = webpath + "/";
            }

            return webpath;
        }
    }


    public static  class StringExtend
    { 

        /// <summary>
        /// GenerateWhere1("GW","监督,宣传,其它","=","and",",")
        /// result is "GW='监督' and GW='宣传' and GW='其它'"
        /// </summary>
        /// <param name="str"></param>
        /// <param name="columnName"></param>
        /// <param name="predication"></param>
        /// <param name="split"></param>
        /// <returns></returns>
        public static string GenerateWhere1(this string str, string columnName, string predication1, string predication2, string split)
        {
            string result = string.Empty;

            string[] splitStr=new string[1];
            splitStr[0]=split;

            string[] splitResult = str.Split(splitStr, StringSplitOptions.RemoveEmptyEntries);

            for (int index = 0; index < splitResult.Length; index++)
            {
                if (index == 0)
                {
                    result += columnName + predication1 + "'" + splitResult[index] + "'";
                }
                else
                {
                    result += predication2 + columnName + predication1 + "'" + splitResult[index] + "'";
                }
            }

           return result;
        }


        /// <summary>
        /// GenerateWhere2("GW","监督,宣传,其它","and",",")
        /// result is "GW like '%监督%' and  GW like '%宣传%' and GW like '%其它%'"
        /// </summary>
        /// <param name="str"></param>
        /// <param name="columnName"></param>
        /// <param name="predication"></param>
        /// <param name="split"></param>
        /// <returns></returns>
        public static string GenerateLike(this string str, string columnName, string predication1, string split)
        {
            string result = string.Empty;

            string[] splitStr = new string[1];
            splitStr[0] = split;

            string[] splitResult = str.Split(splitStr, StringSplitOptions.RemoveEmptyEntries);

            for (int index = 0; index < splitResult.Length; index++)
            {
                if (index == 0)
                {
                    result += columnName + " like '%" + splitResult[index] + "%' ";
                    //result += columnName + predication1 + "'" + splitResult[index] + "'";
                }
                else
                {
                    result += predication1 + " " + columnName + " like '%" + splitResult[index] + "%' "; ;
                }
            }

            return result;
        }

        /// <summary>
        /// /*获取拼接sql的in语句 返回格式 '1','2','3','3','4' 为空返回 '' */
        /// </summary>
        /// <param name="strOriginal">字符串分隔符为 # , |</param>
        /// <returns></returns>
        public static string GetSqlInString(string strOriginal)
        {
            if (strOriginal.IndexOf("'") >= 0)
            {
                return strOriginal;
            }
            string[] strArray = strOriginal.Split(new char[] { '#', ',','|' }, StringSplitOptions.RemoveEmptyEntries);
            string strSplit = "";
            for (int i = 0; i < strArray.Length; i++)
            {
                strSplit += "'" + strArray[i] + "',";
            }
            if (strSplit == "")
                return "''";
            return strSplit.TrimEnd(',');
        }


        #region 应用SQL语句查询
        /// <summary>
        /// 应用SQL计算字符长度
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool SQLLen(this string str,int len)
        {
            return str.Length==len;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="str"></param>
        /// <param name="len"></param>
        /// <param name="Opt"></param>
        /// <returns></returns>
        public static bool SQLCompareToLen(this string str, int len, string Opt)
        {   
            switch (Opt)
            { 
                case ">":
                    return str.Length > len;
                case ">=":
                    return str.Length >= len;
                case "<":
                    return str.Length < len;
                case "<=":
                    return str.Length <= len;
                default:
                    return str.Length == len;
            }
           
        }

        /// <summary>
        /// 与Contains同一方法
        /// </summary>
        /// <param name="str"></param>
        /// <param name="Like_str"></param>
        /// <returns></returns>
        public static bool Like(this string str,string Like_str)
        {
            return str.Contains(Like_str);
        }

        public static bool SQLInArray(this string str, string[] array)
        { 
            return array.Contains(str); 
        }
        public static bool In(this string str, string In_str)
        {
            return In_str.Contains(str);
        }
        #endregion

    }


}
